package com.easylinkin.linkappapi.alarm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.alarm.entity.AlarmTemplate;
import com.easylinkin.linkappapi.alarm.service.AlarmTemplateService;
import com.easylinkin.linkappapi.annotation.CommonOperateLogAnnotate;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.operatelog.constant.LogConstant.LogModule;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

@RestController
@Api(value="告警模板",tags={"告警模板"})
@RequestMapping("/alarm/alarmTemplate")
public class AlarmTemplateController {
    @Autowired
    private AlarmTemplateService alarmTemplateService;

    /**
     * 获取告警模板的分页数据
     * @param requestModel
     * @return
     */
    @ApiOperation("获取告警模板的分页数据")
    @PostMapping("getPage")
    public RestMessage getPage(@RequestBody RequestModel<AlarmTemplate> requestModel) {
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
        Assert.notNull(requestModel.getPage(), "page 不能为空");
        IPage<AlarmTemplate> record = alarmTemplateService.getAlarmTemplates(requestModel.getPage(), requestModel.getCustomQueryParams());
        return RestBuilders.successBuilder().data(record).build();
    }

    /**
     * 获取告警模板的list信息
     * @param alarmTemplate
     * @return
     */
    @ApiOperation("获取告警模板的list信息")
    @PostMapping("get")
    public RestMessage get(@RequestBody AlarmTemplate alarmTemplate) {
        Assert.notNull(alarmTemplate, "alarmTemplate 不能为空");
        List<AlarmTemplate> record = alarmTemplateService.getAlarmTemplates(alarmTemplate);
        return RestBuilders.successBuilder().data(record).build();
    }

    /**
     * 根据id删除告警模板
     * @param alarmTemplate
     * @return
     */
    @ApiOperation("根据id删除告警模板")
    @PostMapping("deleteTemplateById")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_TEMPLATE, desc = "根据id删除告警模板")
    public RestMessage deleteTemplateById(@RequestBody AlarmTemplate alarmTemplate) {

        return RestBuilders.successBuilder(alarmTemplateService.deleteTemplateById(alarmTemplate.getId())).build();
    }

    /**
     * 新增告警模板
     * @param alarmTemplate
     * @return
     */
    @ApiOperation("新增告警模板")
    @PostMapping("addTemplate")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_TEMPLATE, desc = "新增告警模板")
    public RestMessage addAlarmTemplate(@RequestBody AlarmTemplate alarmTemplate) {

        return RestBuilders.successBuilder(alarmTemplateService.addAlarmTemplate(alarmTemplate)).build();
    }

    /**
     * 更新告警模板
     * @param alarmTemplate
     * @return
     */
    @ApiOperation("修改告警模板")
    @PutMapping("updateTemplate")
    @CommonOperateLogAnnotate(module = LogModule.ALARM_TEMPLATE, desc = "修改告警模板")
    public RestMessage updateAlarmTemplate(@RequestBody AlarmTemplate alarmTemplate) {

        return RestBuilders.successBuilder(alarmTemplateService.updateAlarmTemplate(alarmTemplate)).build();
    }
}
